home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- ------------------------------------------------------------------------------*/
-
- /*
-
- purpose To demonstrate use of the PlotIconID and PlotCIconHandle
- Toolbox calls documented in Macintosh Tech Note 306.
- See the TechNote for more information.
-
- Requires System 7 (because that's where the routines are).
- Simply quits for lesser Systems. */
-
- /* WARNING I am unable to safely use transforms other than ttNone
- and ttSelected with small icons. The others crash disasterously
- (some only do so when the window is on a black-and-white
- device). */
-
- /* NOTE: The program "steals" its icons from the System file. If a needed
- icon is missing, the program simply beeps.
- There were no sicn which match the families I used, and no
- icm8 and icm4 icons at all, so the "mini" size is not exercised.
- The technique is the same...see the Tech Note. */
-
- #include <Types.h> /* Based on the "SillyBalls" sample. Some of these */
- #include <Memory.h> /* include files aren't needed. */
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <SegLoad.h>
- #include <GestaltEqu.h>
- #include <IconPlotting.h>
-
- /* Constants */
- #define BallWidth 20
- #define BallHeight 20
- #define BobSize 8 /* Size of text in each ball */
-
- /* Globals */
- Rect windRect;
-
- /* Prototypes */
- void Initialize(void);
- void Icons(void);
-
- /*
- ** Main body of program SillyBalls
- */
- main()
- {
- long version = 0;
- (void) Gestalt(gestaltSystemVersion, &version);
- if ( version >= 0x00000700) {
- Initialize();
-
- Icons();
- do {
- } while (!Button());
- }
- }
-
- /*
- ** Initialize everything for the program, make sure we can run
- */
- void Initialize()
- {
- WindowPtr mainPtr;
- OSErr error;
- SysEnvRec theWorld;
-
- /*
- ** Test the computer to be sure we can do color.
- ** If not we would crash, which would be bad.
- ** If we can’t run, just beep and exit.
- */
- error = SysEnvirons(1, &theWorld);
- if (theWorld.hasColorQD == false) {
- SysBeep(50);
- ExitToShell(); /* If no color QD, we must leave. */
- }
-
- /* Initialize all the needed managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- /*
- ** To make the Random sequences truly random, we need to make the seed start
- ** at a different number. An easy way to do this is to put the current time
- ** and date into the seed. Since it is always incrementing the starting seed
- ** will always be different. Don’t for each call of Random, or the sequence
- ** will no longer be random. Only needed once, here in the init.
- */
- GetDateTime((unsigned long*) &qd.randSeed);
-
- /*
- ** Make a new window for drawing in, and it must be a color window.
- ** The window is full screen size, made smaller to make it more visible.
- */
- windRect = qd.screenBits.bounds;
- InsetRect(&windRect, 50, 50);
- mainPtr = NewCWindow(nil, &windRect, "\pBo3b Land", true, documentProc,
- (WindowPtr) -1, false, 0);
-
- SetPort(mainPtr); /* set window to current graf port */
- TextSize(BobSize); /* smaller font for drawing. */
- }
-
- IconTransformType NextTransform(IconTransformType trans) {
- switch (trans) {
- case ttNone:
- return ttDisabled;
-
- case ttDisabled:
- return ttOffline;
-
- case ttOffline:
- return ttOpen;
-
- case ttOpen:
- return ttSelected;
-
- case ttSelected:
- return ttSelectedDisabled;
-
- case ttSelectedDisabled:
- return ttSelectedOffline;
-
- case ttSelectedOffline:
- return ttSelectedOpen;
-
- case ttSelectedOpen:
- default:
- return ttNone;
- }
- }
-
- IconTransformType NextTint(IconTransformType tint) {
- if ((tint += ttLabel1) > ttLabel7)
- return ttLabel0;
- else
- return tint;
- }
-
- /*
- ** Icons: Draw the icons.
- */
- void Icons()
- {
- Rect bigRect;
- Rect smallRect;
- Rect theCIconRect;
- Rect tintRect;
- Rect smallTintRect;
- Rect tintCIconRect;
- Rect stretchRect;
- Rect crashRect;
- OSErr err;
- CIconHandle theIcon = NULL;
- IconTransformType trans = ttNone;
- IconTransformType tint = ttLabel0;
- SetRect(&bigRect, 20, 20, 53, 53);
- SetRect(&smallRect, 20, 60, 37, 77);
- SetRect(&theCIconRect, 20, 90, 53, 123);
- SetRect(&tintRect, 20, 140, 53, 173);
- SetRect(&smallTintRect, 20, 180, 37, 197);
- SetRect(&tintCIconRect, 20, 210, 53, 243);
- SetRect(&stretchRect, 20, 260, 85, 325);
-
- TextFont(1);
- TextSize(9);
-
- do {
- err = PlotIconID(&bigRect, 0, trans, -3994);
- if (err)
- SysBeep(7);
-
- /* The transforms I'm not allowing here cause serious crashes in some or
- all screen depths when applied to Small (or Mini) icons. Don't do it. */
- if (trans == ttNone || trans == ttSelected) {
- err = PlotIconID(&smallRect, 0, trans, -3994);
- if (err)
- SysBeep(7);
- }
- else {
- SetRect(&crashRect, smallRect.left,
- smallRect.top + 4,
- smallRect.left + 48,
- smallRect.top + 20);
- TextBox("Crash!", 6, &crashRect, teJustLeft);
- }
-
- /* There's no reason not to apply the transform to all tints, but some
- of them are hard to see, so we'll make this row do double duty. */
- err = PlotIconID(&tintRect, 0, tint + ((trans > ttOpen) ? ttNone : trans), -3982);
- if (err)
- SysBeep(7);
-
- err = PlotIconID(&smallTintRect, 0, tint, -16509);
- if (err)
- SysBeep(7);
-
- if (theIcon == NULL)
- theIcon = GetCIcon(-16396);
- if (theIcon != NULL) {
- err = PlotCIconHandle(&theCIconRect, 0, trans, theIcon);
- if (err)
- SysBeep(7);
- }
- if (theIcon != NULL) {
- err = PlotCIconHandle(&tintCIconRect, 0, tint, theIcon);
- if (err)
- SysBeep(7);
- }
- OffsetRect(&bigRect, 50, 0);
- OffsetRect(&smallRect, 50, 0);
- OffsetRect(&tintRect, 50, 0);
- OffsetRect(&smallTintRect, 50, 0);
- OffsetRect(&theCIconRect, 50, 0);
- OffsetRect(&tintCIconRect, 50, 0);
- trans = NextTransform(trans);
- tint = NextTint(tint);
- } while (trans != ttNone);
-
- err = PlotIconID(&stretchRect, 0, ttNone, -16509);
- if (err)
- SysBeep(7);
-
- TextFont(0);
- TextSize(0);
- MoveTo(20, 16);
- DrawString("\pThese rows are drawn with the various transforms:");
- MoveTo(20, 136);
- DrawString("\pThese rows are drawn with the various tints (and 3 transforms):");
- MoveTo(100, 276);
- DrawString("\pDemonstration of PlotIconID and PlotCIconHandle per TN 306.");
- MoveTo(100, 292);
- DrawString("\pThe Tech Note says to use “align” of zero without definition.");
- MoveTo(100, 308);
- DrawString("\pAlign of 0 seems to be draw to fit…see the double-size");
- MoveTo(100, 324);
- DrawString("\pclipboard to the left.");
- MoveTo(140, 356);
- DrawString("\pClick the mouse to continue.");
-
- if (theIcon != NULL)
- DisposCIcon(theIcon);
- }
-